// pages/showlist/showlist.js
//配置云环境
const app = getApp()
wx.cloud.init({
    env: 'cloud1-8gbitjqz4bc93039',
})
const db = wx.cloud.database()
var host = app.globalData.host
var id = 0
Page({
    /**
     * 页面的初始数据
     */
    data: {
        slist: [],
        nalist: [],
        curpage: 1,
        pages: 0,
        prevc: "gray",
        nextc: "black",
        pagesize: 8,
        idx: 0
    },
    showDetail: function (e) {
        console.log(e);
        let curstudent = e.currentTarget.dataset.item;
        console.log(curstudent);
        wx.setStorageSync('showThisStudent', curstudent);
        wx.navigateTo({
            url: 'details/details',
        });
    },
    aniStart: function () {
        this.setData({
            idx: -1
        })
        let that = this
        id = setInterval(function () {
            that.aniNext()
        }, 60)
    },
    getList() {
        var curlist = []
        for (var i = (this.data.curpage - 1) * this.data.pagesize; i < Math.min((this.data.curpage) * this.data.pagesize, app.globalData.sList.length); i++) {
            curlist.push(app.globalData.sList[i])
        }
        this.setData({
            slist: curlist,
            pagesize: curlist.length
        })
        console.log(this.data.list)
    },
    aniNext: function () {
        var idxx = this.data.idx
        idxx++;
        console.log(idxx)
        this.setData({
            idx: idxx
        })
        if (this.data.idx > this.data.pagesize) {
            clearInterval(id)
        }
    },
    goPrev: function () {
        if (this.data.curpage == 1)
            return;
        var cp = this.data.curpage - 1;
        this.setData({
            nextc: "black",
            curpage: cp
        })
        if (this.data.curpage == 1) {
            this.setData({
                prevc: "gray"
            })
        }
        this.getList();
        this.getcolor();
    },
    goNext: function () {
        if (this.data.curpage == this.data.pages)
            return;
        var cp = this.data.curpage + 1;
        this.setData({
            prevc: "black",
            curpage: cp
        })
        if (this.data.curpage == this.data.pages) {
            this.setData({
                nextc: "gray"
            })
        }
        this.getList();
        this.getcolor();
    },
    notice() {
        var noticeName = ""
        for (var i = 0; i < app.globalData.sList.length; i++) {
            if(app.globalData.sList[i].status=="审核不通过")
                noticeName += app.globalData.sList[i].name + ' '
        }
        console.log(noticeName)
        const noticename=JSON.stringify(noticeName)
        wx.navigateTo({
            url: `details/add1notice/add1notice?noticename=${noticename}`
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            curpage: 1
        })
        this.setData({
            pages: Math.ceil(app.globalData.sList.length / this.data.pagesize)
        })
        if (this.data.pages == 1) {
            this.setData({
                nextc: "grey"
            })
        }
        this.getList()
        //处理nalist
        this.setData({
            slist: app.globalData.sList
        })
        var that = this
        var NAlist = []
        for (var i = 0; i < that.data.slist.length; i++) {
            if (that.data.slist[i].time == true)
                NAlist[i] = "有"
            else
                NAlist[i] = "无"
        }
        this.setData({
            nalist: NAlist
        })
        this.aniStart()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})